package pCloud.server;

import pCloud.PCloudFactory;
import pCloud.config.PCloudConfig;
import pCloud.service.AccessControlHandle;
import pCloud.service.CloudServerProtocol;
import pCloud.service.DataServerProxyServerProtHandle;
import pCloud.service.ProtocolHandle;
import pCloud.transport.Communicator;
import pCloud.transport.EndPointTransportHandle;

public class CloudServerAcceptor extends Acceptor {

	DatabaseHandle databaseHandler = null;
	AccessControlHandle accessControlHandler = null;
	
	public CloudServerAcceptor(int port, Communicator comm,
			AccessControlHandle ach) throws Exception {
		super(port, comm);		
		this.accessControlHandler = ach;
		System.out.println("accepting client connection ...");
	}

	@Override
	public EndPointTransportHandle getServerTransportHandle(int port)
			throws Exception {
		EndPointTransportHandle ep = PCloudFactory
				.getEndPointTransportHandle(PCloudConfig
						.getString(PCloudConfig.PCLOUD_TRANSPORT_SERVER));
		ep.initalize("", port);
		return ep;
	}

	@Override
	public ProtocolHandle getNewProtocolHandle() throws Exception {
		CloudServerProtocol csp = (CloudServerProtocol) PCloudFactory
				.getNewProtocolHandleInstance(PCloudConfig
						.getString(PCloudConfig.PCLOUD_CLOUD_SERVER_PROT));

		csp.initCloud(this.accessControlHandler);		
		return csp;
	}

}
